package fr.ssd.sdl.store.jdbc;

import java.sql.SQLException;
import java.sql.Statement;
import java.util.Map;

import fr.ssd.sdl.store.Store;
import fr.ssd.sdl.store.StoreException;
import fr.ssd.sdl.utils.JdbcHelper;

public class JdbcBackend implements Store {

	Statement s;

	@Override
	public void store(String sqlStatement) throws StoreException {
		try {
			s.addBatch(sqlStatement);
		} catch (SQLException e) {
			throw new StoreException(e);
		}
	}

	@Override
	public void init(Map<String, ?> hints) throws StoreException {
		s = JdbcHelper.getInsertStatement();
		try {
			s.clearBatch();
		} catch (SQLException e) {
			throw new StoreException(e);
		}
	}

	@Override
	public void terminate() throws StoreException {
		try {
			s.executeBatch();
		} catch (SQLException e) {
			throw new StoreException(e);
		}
	}

}
